// pages/my/my-newActivity/my-newActivity.js
var request = require('../../../utils/request.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  //小程序api获取用户系统数据
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res)
        that.setData({
          imgHeight: res.windowHeight*0.54,
          //windowHeight--可使用窗口高
          wordTop: res.windowHeight*0.43,
        });
      }
    });
  },

  onShow: function () {
    var that = this;
    that.getToken();
  },

  getToken: function () {
    var that = this;
    // 获取本地存储中的token
    wx.getStorage({
      key: 'token',
      success: function (res) {//有该数据
        console.log(res.data)
        that.setData({
          token: res.data
        })
        var tempToken = res.data;
        //获取新用户优惠列表
        request.getYouHuiList(
          { "session_id": tempToken },
          (res) => {
            console.log(res);
           //type=1新用户
           if(res.data.code == "1"){
             that.setData({
               youhuiList: res.data.data
             })
           }else{
             wx.showModal({
               title: '',
               content: res.data.msg,
               confirmColor: "#ff0000",
             })
           }

          }
        )

      },
      fail: function (res) {
        console.log(res.data)
        //调用授权方法-设置token
        app.getUserInfo();
      }
    })
  },
  goLingqu:function(e){
    console.log(e)
    wx.showModal({
      title: '',
      content:"恭喜您成功领取免费月卡~",
      showCancel:false,
      confirmColor:"#ff0000"
    })
  }
})